Fix NMEA parsing creating Null Island waypoints (#607)
authorViet-Tam Luu <viettaml@google.com>
Sat, 1 Aug 2020 19:57:22 +0000 (12:57 -0700)
committerGitHub <noreply@github.com>
Sat, 1 Aug 2020 19:57:22 +0000 (13:57 -0600)
* Fix NMEA parsing creating Null Island waypoints

Fix parsing of NMEA GPGGA sentences: ones with 0 "fix quality" (i.e. "invalid") are allowed in serial (i.e. live GPS) mode because (according to the comment) some GPS devices will report previously-read data in the absence of a current good fix. Adjust this allowance to require an actual coordinate value; at least one popular USB GPS device will issue GPGGA such as "$GPGGA,010222.00,,,,,0,00,99.99,,,,,,*65" if it loses a good fix, and the empty lat/lng coordinates (",,,,,") are parsed as 0N 0W (a.k.a. "Null Island"). QString::toDouble() won't report a problem with an empty input so we simply check for 0 lat/lng.

* Use "ok" QString::toDouble() argument instead

... of checking for checking for both lat & lng exactly zero, as `ok` does indeed get set to `false` on empty inputs, in recent Qt versions.

* Revert "Use "ok" QString::toDouble() argument instead"

This reverts commit d226d01c862606615aa599f5d3b649cea12f0700.

nmea.cc

diff --git a/nmea.cc b/nmea.cc
index 9de6c7942ae4385c10e04292f1fc8f2dd9b2e91f..6be06f149087fde14fa183805e9f669bf6281d60 100644 (file)
--- a/nmea.cc
+++ b/nmea.cc
@@ -426,11 +426,12 @@ NmeaFormat::gpgga_parse(char* ibuf)
 
   /*
    * In serial mode, allow the fix with an invalid position through
+   * (unless if the position lat/lng is absent or completely bogus)
    * as serial units will often spit a remembered position up and
    * that is more comfortable than nothing at all...
    */
   CHECK_BOOL(opt_ignorefix);
-  if ((fix <= 0) && (read_mode != rm_serial) && (!opt_ignorefix)) {
+  if ((fix <= 0) && (read_mode != rm_serial || (latdeg == 0.0 && lngdeg == 0.0)) && (!opt_ignorefix)) {
     return;
   }